#ifndef PLAYLIST_H
#define PLAYLIST_H

#include<QList>
#include<QObject>
#include<QPointer>

// #include"CommonException.h"
#include"TrackProgression.h"
class Song;

/*
 * Song class
 * After initialization, should NOT have a current Song yet. A call to next() should be required first.
 */


class Playlist: public QObject{
Q_OBJECT
public:
	Playlist();
	Playlist(Playlist *other);//Move contents of other into this. Other can be deleted after this operation.
	virtual ~Playlist();
	
	bool isEmpty()const;
	virtual bool previous();
	bool prev(){ return previous(); }
	virtual bool next();
	QPointer<Song> current()const;
	
	void clear();
	
	virtual void setIndex(short int index);//Force song at index to be "current"
	void reset(){ setIndex(-1); }
	
	unsigned numSongs()const{ return m_songs.size(); }
	QPointer<Song> song(unsigned i)const{ return m_songs[i]; }
	
	TrackProgression::ProgressionType progressionType()const;
	TrackProgression::RepeatType repeatType()const;
	void setProgression(TrackProgression::ProgressionType progression, TrackProgression::RepeatType repeat);
	
	QString progressionText()const;
	QString repeatText()const;
public slots:
	void add(QPointer<Song> song, short int index = -1);
	void add(const QString &songPath, short int index = -1);
	void add(QList<QString> songs);
	void slotRemoveSongs(QList<short int> indices);
	void slotRemoveSong(short int index);
protected:
	virtual void _clear() {}
	virtual void _addSong(QPointer<Song>,short int) {}
	QList< QPointer<Song> > m_songs;
	TrackProgression *m_trackProgression;
private:
	short int m_index;
signals:
	void cleared();
	void currentChanged(short int)const;
	void nowPlaying(QPointer<Song>)const;
	void songAdded(QPointer<Song>, short int);
	void songRemoved(short int);
	
};

#endif
